from math import cos, sin, sqrt, pi, atan, acos


class Fracture2:
    __vdict = {'dir':0, 'dip':0}
    __vdict_name = locals().keys()[0]
    def __init__(self):        
        self.__dict__[self.__vdict_name] = {}        
    def __getattr__(self, name):
        return self.__vdict[name]
    def __setattr__(self, name, value):
        self.__vdict[name] = value
        self.__vdict['cos1'], self.__vdict['cos2'], self.__vdict['cos3'], \
        self.__vdict['sin1'], self.__vdict['sin2'], self.__vdict['sin3'] = \
        get_cos_sin(self.__vdict['dir'], self.__vdict['dip'])

class Fracture:
    def __init__(self):        
        self.dir = 0
        self.dip = 0
        self.refresh()
    def refresh(self):
        self.cos1, self.cos2, self.cos3, self.sin1, self.sin2, self.sin3 = \
        get_cos_sin(self.dir, self.dip)
        	
def get_cos_sin(dr, dp):
    dr = dr * pi / 180; dp = dp  * pi / 180
    cos1 = cos(dr) * cos(dp) 
    cos2 = sin(dp)
    cos3 = sin(dr) * cos(dp)
    sin1 = sqrt(1 - cos1**2)
    sin2 = sqrt(1 - cos2**2)
    sin3 = sqrt(1 - cos3**2)    
    return cos1,cos2,cos3,sin1,sin2,sin3

class MyClass:
    def __init__(self):
        self.a = 0
        self.b = 1
        

class MyClass2:
    mdict = {}
    def __init__(self):
        self.mdict = {}    
    def __setattr__(self, name, value):
        self.mdict[name] = value
    def __getattr__(self, name):
        return self.mdict[name]

def get_angel(a, b):
    return acos((a.cos1 * b.cos1 + a.cos2 * b.cos2 + a.cos3 * b.cos3 ) / \
    sqrt((a.cos1**2 + a.cos2**2 + a.cos3**2) * (b.cos1**2 + b.cos2**2 + b.cos3**2))) \
    *180/pi

def main():
    a = Fracture()
    b = Fracture()    

    for ddir in range(0, 361, 45):
        for ddip in range(0, 181, 45):
            a.dir, a.dip = ddir, ddip
            a.refresh()
            #print "%03d, %02d \t %1.2f, %1.2f, %1.2f" % (a.dir, a.dip, a.cos1, a.cos2, a.cos3)
            print "%03d, %02d \t %03d, %02d \t %03d" % \
                                (b.dir, b.dip, a.dir, a.dip, get_angel(a, b))


def main_():
    a_ = MyClass()
    b_ = MyClass()
    a__ = MyClass2()
    b__ = MyClass2()
    #b.dir, b.dip = 15, 60
    print a_.a, a_.b, b_.a, b_.b
    a_.a = 10 
    print a_.a, a_.b, b_.a, b_.b
    #print a__.a, a__.b, b__.a, b__.b
    a__.a = 10 
    b__.a = 0
    print a__.a, b__.a


if __name__=='__main__':
    main()
